package com.example.springboot.config;

import com.example.springboot.Interceptor.PermissionInterceptor;
import com.example.springboot.Interceptor.TokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Resource
    private TokenInterceptor tokenInterceptor;

    @Resource
    private PermissionInterceptor permissionInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .order(1);

        registry.addInterceptor(permissionInterceptor)
                .excludePathPatterns("/") // 添加排除模式
                .excludePathPatterns("/user/checkCode") // 添加排除模式
                .excludePathPatterns("/user/login") // 添加排除模式
                .excludePathPatterns("/user/logout") // 添加排除模式
                .addPathPatterns("/**")
                .order(2);
    }

}
